package hacker_rank.codesprint5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SpecialMultiple {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());

		for (int t = 0; t < T; t++) {
			int N = Integer.parseInt(br.readLine());
			solve(N);
		}
	}

	static void solve(int n) {
		long res = 1;
		long t = 1;
		for (;;) {
			t = Long.valueOf(Long.toBinaryString(res));
			if ((t * 9) % n == 0) {
				break;
			}
			res++;
		}
		System.out.println(t * 9);
	}

}
